package com.smart.wap.app;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.smart.common.entities.ajax.AjaxResult;
import com.smart.common.entities.constant.SmartConstant;
import com.smart.common.entities.core.BaseSearch;
import com.smart.common.entities.core.Page;
import com.smart.manager.union.mall.body.RUnionMallOrder;
import com.smart.manager.union.mall.models.UnionMallGoods;
import com.smart.manager.union.mall.models.UnionMallOrder;
import com.smart.manager.union.mall.repository.UnionMallGoodsRepository;
import com.smart.manager.union.mall.repository.UnionMallOrderRepository;
import com.smart.utils.MemberAcl;
import com.smart.utils.MemberStp;
import com.smart.wap.bodys.UnionMallBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @author Administrator
 */

@Api(tags = "移动端-商城接口")
@RestController
@Log4j2
@RequestMapping(SmartConstant.WAP_API_PREFIX + "app/union/mall")
@RequiredArgsConstructor
public class MallController {

    private final UnionMallGoodsRepository goodsRepository;

    private final UnionMallOrderRepository orderRepository ;


    @ApiOperation(value = "获取商品列表")
    @GetMapping(value = "getGoodsPageList")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<Page<UnionMallGoods>> getPageList(@Validated UnionMallBody.SearchBody search) {
        Page<UnionMallGoods> result = goodsRepository.getGoodsPageList(search);
        return AjaxResult.data(result);
    }


    @ApiOperation(value = "创建实物订单")
    @PostMapping(value = "createMallOrder")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<String> createMallOrder( @RequestBody @Validated RUnionMallOrder.CreateBody createBody) {
        Long memberId = MemberAcl.getLoginId();
        orderRepository.createOrder(memberId, createBody);
        return AjaxResult.success();
    }





    @ApiOperation(value = "获取我的实物订单")
    @GetMapping(value = "getMyMallOrderList")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<Page<UnionMallOrder>> getMyMallOrderList(@Validated BaseSearch baseSearch) {
        Long memberId = MemberAcl.getLoginId();
        Page<UnionMallOrder> result = orderRepository.getMyPageList(memberId, baseSearch);
        return AjaxResult.data(result);
    }





}
